<?php
class DBhandler {
	
	
	public $dbHost;
	public $dbUser;
	public $dbPass;
	public $dbName;
	
	function DBhandler() {
		$this -> dbHost = _dbHost_;
		$this -> dbUser = _dbUser_;
		$this -> dbPass = _dbPass_;
		$this -> dbName = _dbName_;
		$this -> dbconnect();
	}
	
	public function dbconnect() {
		$connect = @mysql_connect($this -> dbHost, $this -> dbUser, $this -> dbPass)
				 or die ("Verbindung zur Datenbank konnte nicht hergestellt werden!");

		$selectDB = @mysql_select_db($this -> dbName, $connect)
				 or die ("Die Datenbank <b>$dbName</b> konnte nicht gefunden werden");
		
		
	}
	
	
	public function fetch_first_row($select) {
		return mysql_fetch_array(mysql_query($select), MYSQL_ASSOC);
	}
	
	public function fetch_all_array ($select, $method = MYSQL_ASSOC) {
		$a=0;
		$result = array();
		$res = mysql_query($select);
		while ($row = mysql_fetch_array($res, $method)) {
			foreach ($row as $key => $value) {
				$result[$a][$key] = $value; 
			}
			$a++;
		}
		return $result;
	}
	
	
	public function  insert_row($insert, $primary = FALSE) {
		mysql_query($insert);
		$id = -1;
		$id = $primary == TRUE ? mysql_insert_id() : -1;
		return $id;	
	}
	
	public function update_row($update) {
		mysql_query($update);
	}
	
	public function delete_row($delete) {
		mysql_query($delete);
	}
	
	public function fetch_first_string($select, $string) {
		$result = array();
		$result = mysql_fetch_array(mysql_query($select), MYSQL_ASSOC);
		return $result[$string];
	}
	
	
}
?>
